package lc.inte;

import lc.ListNode;

import java.util.HashSet;
import java.util.Set;

/**
 * 编写代码，移除未排序链表中的重复节点。保留最开始出现的节点。
 */
public class Q0201 {

    public ListNode removeDuplicateNodes(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode oh = head;
        Set<Integer> v = new HashSet<>();
        while (head.next != null) {
            v.add(head.val);
            if (v.contains(head.next.val)) {
                head.next = head.next.next;
            } else {
                head = head.next;
            }
        }
        return oh;
    }

    public static void main(String[] args) {

    }

}
